package com.admin.education.controllers.api.v1;

import com.admin.education.common.exceptions.BadRequestException;
import com.admin.education.common.response.IResponseMessage;
import com.admin.education.common.response.ResponseMessageWithData;
import com.admin.education.common.response.Result;
import com.admin.education.dataTransferObject.ServicesExcuteResult;
import com.admin.education.dataTransferObject.icons.IconsTransfer;
import com.admin.education.services.Interfaces.IIconsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.Callable;

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/v1/icons")
public class IconsController {
    @Autowired
    private IIconsService iconsService;
    @GetMapping("")
    public Callable<IResponseMessage> queryIcons(){
        return ()->{
            IResponseMessage responseMessage =null;

            ServicesExcuteResult<List<IconsTransfer>> result = this.iconsService.queryIcons();

            if(result.isSuccess()){
                responseMessage = new ResponseMessageWithData<List<IconsTransfer>>(Result.Success,result.getData());
            }
            else
                throw new BadRequestException(result.getErrorMessage());
            return  responseMessage;
        };
    }
}
